home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3261 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.4 KB  |  72 lines

  1. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  2. Path: shrike.irvine.com!adam
  3. From: adam@irvine.com (Adam Beneschan)
  4. Subject: Re: Avoiding typedefs (was: Hungarian notation)
  5. In-Reply-To: Douglas Evan Cook's message of Mon, 22 Jan 1996 14:58:59 -0700
  6. References: <30C40F77.53B5@swsbbs.com> <4bd <4cc2b2$11jq@navajo.gate.net>
  7.  <4cud8f$gup@news.netvision.net.il> <4dttefINNo29@keats.ugrad.cs.ubc.ca> <Pine.HPP.3.91.960122145028.27524A-100000@clear.cs.byu.edu>
  8. Sender: usenet@irvine.com (News Administration)
  9. Organization: Irvine Compiler Corp., Irvine, California, USA
  10. Date: Tue, 23 Jan 1996 02:16:36 GMT
  11. Message-ID: <DLM3no.4M6@irvine.com>
  12.  
  13. Douglas Evan Cook <cookd@cs.byu.edu> writes:
  14.  
  15. > On 21 Jan 1996, Kazimir Kylheku wrote:
  16. >
  17. > > I say, don't bother. I avoid typedefs like the plague, even for structures. I
  18. > > much rather write the longer form.
  19. > > 
  20. > >     void myfunction(struct whatever *x);
  21. > > 
  22. > > Using excessive typedefs will just occlude your code. What is the point of
  23. > > having a separate type for MSEC? Later, when someone sees a declaration of a
  24. > > variable of type MSEC, he will have to go hunting and pecking for the
  25. > > definition of MSEC. It _obviously_ stands for milliseconds, but what the hell
  26. > > is it? 
  27.  
  28. If MSEC obviously stands for milliseconds, then the answer to the
  29. question "what the heck is it" is "Milliseconds".  If you care at that
  30. point how "milliseconds" is implemented, you need to go back and
  31. relearn about "abstraction" and why it's important.
  32.  
  33. I'll grant that this isn't all that helpful in C, which doesn't
  34. contain a whole lot of support for abstract data types; so you pretty
  35. much *do* have to know what type of variable it is if you're going to
  36. use it.  In C++ or Ada83 or Ada95 or UCSD Pascal or Modula or Eiffel,
  37. which do provide constructs allow you to define all the operations on
  38. a type in one place so you don't have to worry about it later, calling
  39. things by abstract type names without worrying about how they're
  40. implemented is an absolute MUST.  (By the way, in response to an
  41. earlier post, THIS is the reason for having named types in those
  42. languages---NOT lazy compiler implementors.)
  43.  
  44. > The way I was taught, you use typedefs only for variables that are likely 
  45. > to change type (and you want to change all of the instances of that type 
  46. > at once) and for cross-platform portability (in a multi-language 
  47. > environment like Windows or when you are saving data to disk).  Using it 
  48. > for most other things will, as you said, only hamper coding and debugging 
  49. > efforts.  However, to use those examples to induce "typedefs are useless" 
  50. > is jumping to a bad conclusion.  If you want to argue that the uses that 
  51. > I gave are bad, we can do that, but to generalize without looking at all 
  52. > potential uses isn't a good idea.
  53.  
  54. I must be missing something.  How does
  55.  
  56.         void myfunction (Whatever *x);
  57.  
  58. (where Whatever is a typedef) "occlude your code" or "hamper coding
  59. and debugging efforts", while
  60.  
  61.         void myfunction (struct whatever *x);
  62.  
  63. doesn't?  The second example looks just like the first, in that you're
  64. declaring a variable using some name that I'd have to go somewhere
  65. else and look up if I wanted to see how it was implemented.  The only
  66. difference is a keyword.
  67.  
  68. Or does the character sequence "struct" have some magical properties
  69. that cause occlusion to break up and everything to become clear?
  70.  
  71.                                 -- Adam
  72.